package com.sc.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sc.domain.Storage;
import com.sc.dto.StorageDto;
import com.sc.mapper.StorageMapper;
import com.sc.service.StorageService;
import com.sc.vo.StorageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: Rui
 * @Date: 2024/11/27 13:48
 */
@Service
public class StorageServiceImpl implements StorageService {
    @Autowired
    private StorageMapper storageMapper;

    @Override
    public boolean addStorage(Storage storage) {
        return storageMapper.addStorage(storage);
    }

    @Override
    public boolean deleteStorageById(Long id) {
        return storageMapper.deleteStorageById(id);
    }

    @Override
    public boolean updateStorage(Storage storage) {
        return storageMapper.updateStorage(storage);
    }

    @Override
    public Map<String, Object> pageQuery(StorageDto stroageDTO) {
        PageHelper.startPage(stroageDTO.getPage(), stroageDTO.getPageSize());
        Page<StorageVo> info=storageMapper.pageQuery(stroageDTO);
        Map<String,Object> map=new HashMap<>();
        map.put("total",info.getTotal());
        map.put("pageSize",info.getPageSize());
        map.put("pageNumber",info.getPageNum());
        map.put("data",info.getResult());
        return map;
    }

    @Override
    public Storage selectById(Long id) {
        return storageMapper.selectById(id);
    }

    @Override
    public boolean deleteStorageByIds(List<Integer> ids) {
        return storageMapper.deleteStorageByIds(ids);
    }
}
